package Game;
import java.io.File;
import java.io.Serializable;

/**
 * This is the list of all available items in the system
 * 
 * @author Ryan Goodrich
 * @version 1.0
 * @extends FileInput
 *
 */
public class ItemList extends FileInput {
	
	/**
	 * Create the Item List object using the item's file data
	 */
	private static String folder = System.getProperty("user.dir")+ File.separator;
	public ItemList() {
		super(folder+"support"+File.separator+"Items.txt");
	}
	
	/**
	 * Returns the name of them item
	 * 
	 * @param itemId Id of the item being requested
	 * @return Name of item requested, null if itemId is not valid
	 */
	public String getItemName(int itemId) {
		if (!checkIndex(itemId))
			return null;
		return getRawDataAt(itemId).get("name");
	}
	
	/**
	 * Returns the file name of them item
	 * 
	 * @param itemId Id of the item being requested
	 * @return File name of item requested, null if itemId is not valid
	 */
	public String getItemPictureFile(int itemId) {
		if (!checkIndex(itemId))
			return null;
		return getItemName(itemId).replace(' ', '_').toLowerCase() + ".png";
	}
	
	/**
	 * Returns the weight of them item
	 * 
	 * @param itemId Id of the item being requested
	 * @return Weight of item requested, 0 if itemId is not valid
	 */
	public int getItemWeight(int itemId) {
		if (!checkIndex(itemId))
			return 0;
		return Integer.parseInt(getRawDataAt(itemId).get("weight"));
	}

	/**
	 * Returns the price of them item
	 * 
	 * @param itemId Id of the item being requested
	 * @return Price of item requested, 0 if itemId is not valid
	 */
	public int getItemPrice(int itemId) {
		if (!checkIndex(itemId))
			return 0;
		return Integer.parseInt(getRawDataAt(itemId).get("price"));
	}
}
